<%
=begin
apps: metallb
platforms: kubernetes, tanzu-application-catalog
id: configure_layer2_mode
title: Configure MetalLB in layer 2 mode
category: administration
weight: 20
highlight: 20
=end %>

The layer 2 mode is commonly used to make MetalLB behave as a load-balancer. When configuring MetalLB in layer 2 mode, all traffic for a service IP goes to one node. From there, *kube-proxy* spreads the traffic to all the service's pods.

This mode doesn't implement a load-balancer, it is most likely a failover mechanism: when one node is down, is automatically detected and the rest of the nodes will take over the ownership of the failed node IP addresses.

Find below an example of how to enable the layer 2 mode. Note that the IP addresses shown in the "addresses" section are part of a subset of the cluster available service IPs.

~~~
configInline:
  # The address-pools section lists the IP addresses that MetalLB is
  # allowed to allocate, along with settings for how to advertise
  # those addresses over BGP once assigned. You can have as many
  # address pools as you want.
  address-pools:
  - # A name for the address pool. Services can request allocation
    # from a specific address pool using this name, by listing this
    # name under the 'metallb.universe.tf/address-pool' annotation.
    name: generic-cluster-pool
    # Protocol can be used to select how the announcement is done.
    # Supported values are bgp and layer2.
    protocol: layer2
    # A list of IP address ranges over which MetalLB has
    # authority. You can list multiple ranges in a single pool, they
    # will all share the same settings. Each range can be either a
    # CIDR prefix, or an explicit start-end range of IPs.
    addresses:
    - 10.27.50.30-10.27.50.35
~~~

